//
//  TableViewCell.m
//  AutoLayoutDemo
//
//  Created by Han on 15-3-30.
//  Copyright (c) 2015年 IPingLun. All rights reserved.
//

#import "TableViewCell.h"
#define MAIN_SCREEN_WIDTH [[UIScreen mainScreen]bounds].size.width

@implementation TableViewCell



@synthesize mLabel;

- (void)awakeFromNib {
    // Initialization code
}


-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        
        mLabel = UILabel.new;
        //mLabel.backgroundColor = [UIColor grayColor];
        mLabel.translatesAutoresizingMaskIntoConstraints = NO;
        mLabel.font = [UIFont systemFontOfSize:16.0];
        mLabel.numberOfLines = 0;
        mLabel.lineBreakMode = NSLineBreakByWordWrapping;
        [self addSubview:mLabel];
        
        [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[mLabel]-20-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(mLabel)]];

        //[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[mLabel]-0-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(mLabel)]];
        
        //NSLog(@"%f", mLabel.frame.size.height);
    }
    
    return self;
}



- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

/*
- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
    CGContextFillRect(context, rect);
    
    //上分割线，
    //CGContextSetStrokeColorWithColor(context, [UIColor clearColor].CGColor);
    //CGContextStrokeRect(context, CGRectMake(5, -1, rect.size.width - 10, 1));
    
    //下分割线
    CGContextSetStrokeColorWithColor(context, [UIColor greenColor].CGColor);
    CGContextStrokeRect(context, CGRectMake(10, rect.size.height, rect.size.width - 20, 0.5));
}
*/

+ (float) getLabelHeight:(NSString *)text {
    
    UILabel *label = UILabel.new;
    label.numberOfLines = 0;
    label.lineBreakMode = NSLineBreakByWordWrapping;
    label.text = text;
    
    UIFont *font = [UIFont systemFontOfSize:16.0];
    
    CGSize size = CGSizeMake(MAIN_SCREEN_WIDTH - 40, 200);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:font, NSFontAttributeName, nil];
    
    return [text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil].size.height + 1;
    
}

@end
